package xyz.ytfs.entity;

import org.springframework.test.context.ContextConfiguration;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * @Classname Customer
 * @Description TODO(客户的实体类)
 * @Date 2020/5/8 23:20
 * @Created by ytfs
 */

@Entity
@Table(name = "cst_customer")
public class Customer {
    /**
     * CREATE TABLE `cst_linkman` (
     * `lkm_id` bigint(32) NOT NULL AUTO_INCREMENT COMMENT '联系人编号(主键)',
     * `lkm_name` varchar(16) DEFAULT NULL COMMENT '联系人姓名',
     * `lkm_gender` char(1) DEFAULT NULL COMMENT '联系人性别',
     * `lkm_phone` varchar(16) DEFAULT NULL COMMENT '联系人办公电话',
     * `lkm_mobile` varchar(16) DEFAULT NULL COMMENT '联系人手机',
     * `lkm_email` varchar(64) DEFAULT NULL COMMENT '联系人邮箱',
     * `lkm_position` varchar(16) DEFAULT NULL COMMENT '联系人职位',
     * `lkm_memo` varchar(512) DEFAULT NULL COMMENT '联系人备注',
     * `lkm_cust_id` bigint(32) NOT NULL COMMENT '客户id(外键)',
     * PRIMARY KEY (`lkm_id`),
     * KEY `FK_cst_linkman_lkm_cust_id` (`lkm_cust_id`),
     * CONSTRAINT `FK_cst_linkman_lkm_cust_id` FOREIGN KEY (`lkm_cust_id`) REFERENCES `cst_customer` (`cust_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
     * ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
     */

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "cust_id")
    private Long custId;

    @Column(name = "cust_name")
    private String custName;

    @Column(name = "cust_source")
    private String custSource;

    @Column(name = "cust_industry")
    private String custIndustry;

    @Column(name = "cust_level")
    private String custLevel;

    @Column(name = "cust_address")
    private String custAddress;

    @Column(name = "cust_phone")
    private String custPhone;

    /*
    表达一对多的关系
     */
    /**
     *  * 使用注解的形式配置多表关系
     *            1.声明关系
     *                @OneToMany : 配置一对多关系
     *                    targetEntity ：对方对象的字节码对象
     *            2.配置外键（中间表）
     *                    @JoinColumn : 配置外键
     *                        name：外键字段名称
     *                        referencedColumnName：参照的主表的主键字段名称
     *
     *        *在客户实体类上（一的一方）添加了外键了配置，所以对于客户而言，也具备了维护外键的作用
     */
    //@OneToMany(targetEntity = LinkMan.class)
    //@JoinColumn(name = "lkm_cust_id", referencedColumnName = "cust_id")
    /**
     * 放弃外键维护权
     * mappedBy：对方配置关系的属性名称\  这里就是值得LinkMan中Customer对象得变量名称
     * cascade : 配置级联（可以配置到设置多表的映射关系的注解上）
     * CascadeType.all         : 所有
     * MERGE       ：更新
     * PERSIST     ：保存
     * REMOVE      ：删除
     * <p>
     * fetch : 配置关联对象的加载方式
     * EAGER   ：立即加载
     * LAZY    ：延迟加载
     */
    @OneToMany(mappedBy = "customer", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private Set<LinkMan> linkMans = new HashSet<>();

    public Long getCustId() {
        return custId;
    }

    public void setCustId(Long custId) {
        this.custId = custId;
    }

    public String getCustName() {
        return custName;
    }

    public void setCustName(String custName) {
        this.custName = custName;
    }

    public String getCustSource() {
        return custSource;
    }

    public void setCustSource(String custSource) {
        this.custSource = custSource;
    }

    public String getCustIndustry() {
        return custIndustry;
    }

    public void setCustIndustry(String custIndustry) {
        this.custIndustry = custIndustry;
    }

    public String getCustLevel() {
        return custLevel;
    }

    public void setCustLevel(String custLevel) {
        this.custLevel = custLevel;
    }

    public String getCustAddress() {
        return custAddress;
    }

    public void setCustAddress(String custAddress) {
        this.custAddress = custAddress;
    }

    public String getCustPhone() {
        return custPhone;
    }

    public void setCustPhone(String custPhone) {
        this.custPhone = custPhone;
    }

    public Set<LinkMan> getLinkMans() {
        return linkMans;
    }

    public void setLinkMans(Set<LinkMan> linkMans) {
        this.linkMans = linkMans;
    }

    @Override
    public String toString() {
        return "Customer{" +
                "custId=" + custId +
                ", custName='" + custName + '\'' +
                ", custSource='" + custSource + '\'' +
                ", custIndustry='" + custIndustry + '\'' +
                ", custLevel='" + custLevel + '\'' +
                ", custAddress='" + custAddress + '\'' +
                ", custPhone='" + custPhone + '\'' +
                '}';
    }
}
